package com.orbitdevs.testgame.input;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;

public class TouchScreenRegion {
	private float WIDTH;
	private float HEIGHT;
	private float XPOS;
	private float YPOS;
	public boolean touched = false;
	public boolean prevTouched = false;
	private Array<float[]> dPosStore = new Array<float[]>(10);
	
	public TouchScreenRegion(float h, float w, float x, float y){
		this.WIDTH = w;
		this.HEIGHT = h;
		this.XPOS = x;
		this.YPOS = y;
	}
	
	public boolean contains(float x, float y){
		if (x > this.XPOS && x < this.WIDTH + this.XPOS && y > this.YPOS && y < this.YPOS + this.HEIGHT){
			return true;
		}
		else{
			return false;
		}
	}
	
	public void touchRec(){
		dPosStore.add(new float[] {Gdx.input.getDeltaX(), Gdx.input.getDeltaY()});
	}
	
	public float[] getTouchVal(boolean right){
		float x = 0, y = 0;
		for(float[] i : dPosStore){
			x += i[0];
			y += i[1];
		}
		if(right){
			dPosStore.clear();
		}
		return new float[] {x,y};
	}
	
	public void clearRec(){
		dPosStore.clear();
	}
	
	public boolean isTouched(){
		int x1 = Gdx.input.getX();
		int y1 = Gdx.input.getY();
		if(Gdx.input.isTouched() && this.contains(x1, y1)){
			prevTouched = true;
			touched = true;
			return true;
		}
		else{
			return false;
		}
	}
	
	public void setTouched(boolean touched){
		this.touched = touched;
	}
}
